// pages/index/orderdetails.js
var util = require('../../utils/util.js');
var amap = require('../../utils/amap-wx.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderId:'',
    orderData:'',
    addalltime:'',  //2018.11.12 12:24
    addtime: '',    //2018.11.12
    deadline: '',   //2018.11.12
    isHidden:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '订单详情'
    })
    var that = this;
    that.setData({
      orderId: options.id
    });
    that.getOrderDetail();
  },
  // 拨打电话
  bind_tal: function () {
    var that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.orderData.phone //仅为示例，并非真实的电话号码
    })
  },
  /**
   * 到这去
   */
  tapMap: function () {
    var that = this
    wx.showLoading({ title: '正在定位...' });
    //地理位置==>地理坐标
    var url_address = util.GaoName.shop_coordinate
    wx.request({
      url: url_address,
      data: {
        key: util.GaoName.GaodeKey,
        address: that.data.orderData.address,
        output: 'JSON',
      },
      method: 'GET',
      success: function (data) {
        wx.hideLoading();
        var location_1 = data.data.geocodes[0].location.split(',');
        that.setData({
          longitude: location_1[0],
          latitude: location_1[1],
        });
        that.openShopLocation();
      },
      fail: function (e) {
        wx.hideLoading();
        wx.showModal({
          title: '提示',
          content: '位置获取失败',
          confirmColor: '#5599ff',
          success: function (res) {
            if (res.confirm) { } else if (res.cancel) { }
          }
        })
      }
    })
  },
  //当前店铺位置信息
  openShopLocation: function () {
    var that = this;
    wx.openLocation({
      longitude: parseFloat(that.data.longitude),
      latitude: parseFloat(that.data.latitude),
      name: that.data.orderData.storename,
      address: that.data.orderData.address
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
   * 订单详情
   */
  getOrderDetail: function () {
    var that = this;
    wx.showLoading({ title: '加载中' });
    var url = util.URL.order_detail + '?id=' + that.data.orderId;
    util.GET(url, function (sData) {
      wx.hideLoading();
      that.setData({
        orderData: sData.info,
        isHidden: false
      })  
      var addtime = that.data.orderData.addtime;
      var deadline = that.data.orderData.deadline;
      that.setData({
        addalltime: util.formatDivTime(addtime, 'Y.M.D h:m'),
        addtime: util.formatDivTime(addtime, 'Y.M.D'),
        deadline: util.formatDivTime(deadline, 'Y.M.D')
      });
    }, function (eData) {
      wx.hideLoading();
    });
  }
})